package com.maixin.code.utils;

import java.util.ArrayList;
import java.util.List;

import com.maixin.code.entity.DataDictionary;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class Json2JavaUtils {
	/**
	 * 将JSON数据的字符串转换成指定类型clazz的集合
	 * @param json JSON字符串
	 * @param clazz 指定类型clazz
	 * @return List
	 */
	public static List json2Java(String json,Class clazz){
	//	json = "[{'dictName':'123','itemId':'','value1':'','value2':'','perantId':'我还','remark':''}]";
		List<Object> list = new ArrayList();
		JSONArray array = JSONArray.fromObject(json); 
		for (int i = 0; i < array.size(); i++) {
			 JSONObject jsonObject = array.getJSONObject(i);        
			 list.add(JSONObject.toBean(jsonObject, clazz));  
		}
		return list;
		
	}
	public static void main(String[] args) {
		Json2JavaUtils.json2Java("", DataDictionary.class);
	}
}
